/**
 * Created by Hancock on 2017/7/20.
 */
import React from 'react';
import {Link} from 'react-router';
import {hashHistory} from 'react-router';
import {Button} from 'antd';
import 'antd/dist/antd.css';  // or 'antd/dist/antd.less'
import $ from "jquery";
require("./SignIn.css");

export default class SignIn extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            id: "",
            password: "",
        }
    }

    handleSubmit = (e) => {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "http://123.207.214.129:9090/LanOu/login",
            data: {
                id: this.state.id,
                password: this.state.password,
            },
            dataType: "json",
            success: (data) => {
                if (data.msg === "成功") {
                    console.log(data);
                    window.sessionStorage.setItem('userStorage', JSON.stringify(data));
                    hashHistory.push("/");
                } else {

                }
                console.log(data);
            },
            error: function (e) {
                console.log(e);
            }
        });
    };

    render() {
        return (
            <div className="login">
                <div className="headerTop">
                    <div className="logo">
                        <img src="images/logo.png"/>
                    </div>
                </div>
                <div className="main">
                    <div className="mainLeft">
                        <h3><span>账号密码登录</span></h3>
                        <form onSubmit={(e) => {
                            this.handleSubmit(e)
                        }}>
                            <input className="text" type="text" placeholder="账户名"
                                   onChange={(e) => {
                                       this.setState({
                                           id: e.target.value
                                       });
                                   }}/>
                            <input type="password" name="" placeholder="密码"
                                   onChange={(e) => {
                                       this.setState({
                                           password: e.target.value
                                       });
                                   }}/>
                            <div>
                                <Button type="default" htmlType="submit" className="a" href="#">登录</Button>
                                <a className="forgetpsd"> <Link to="/ChangePwd">忘记密码？</Link></a>
                            </div>
                        </form>

                    </div>
                    <div className="mainRight">
                        <img className="img" src="../images/bg_login.jpg"/>
                    </div>
                </div>
            </div>

        );
    };
}